//添加商品
$("#addBlog").on("click",function(e){
	
	
	var flag = true ;
	var blogId= $("#blogId").val();
	var title = $("#title").val();
	if (checkReg(title, "#tTip")){
		flag = false ;
	}
	var content = $("#blogContent").val();
	if (checkReg(content, "#cTip")){
		flag = false ;
	}
	var date = $("#date").val();
	if (checkReg(date, "#dTip")){
		flag = false ;
	}
	var publisher = $('input:radio:checked').val();
	if (checkReg(publisher, "#uTip")){
		flag = false ;
	}
	//获取到一级分类的select对象
	var cateCategoryObj = $("#firstLevelProductCategory")[0];
	//获取到分类id
	var firstCategoryId = cateCategoryObj.options[cateCategoryObj.selectedIndex].value;
	var ischecked = $("input[type='checkbox']").is(':checked');
	if(flag){
		var ispublished = 0 ;
		if(ischecked){
			ispublished = 1 ;
		}
		// 拼装商品信息
		var blog = {
		    "blogId":blogId,
			"oneLevelCategoryId" : firstCategoryId,
			"title" : title,
			"content" : content,
			"surfacePlot" : null,
			"createTime" : analysisDate(date).getTime(),
			"publisher" : publisher,
			"ispublished" : ispublished
		}
		alert(JSON.stringify(blog));
		var url = base_url + "admin/updateBlog";
		//封装参数
		var params = {
				"mapAttr":JSON.stringify(blog)
		}
		//进行请求
		post(url, params);
	}
		
});

function analysisDate(date){
	var d = date.split("/");
	var str = d[2] + "-" + d[1] + "-" + d[0]+" 00:00:00";
	var date = new Date();
	date.setFullYear(d[2], d[1], d[0]);
	return date ;
}


//进行格式的检验
function checkReg(obj1, obj2) {

	//如果为空或者不是字符串，则把标志设置成false
	if (obj1 == null || obj1 == "" || obj1 == undefined) {
		$(obj2).show();
		return true;
	}else{
		$(obj2).hide();
	}
	return false ;
}

//判断图片是否没有选择
function checkImage(obj1, obj2){
	
	if (obj1 == null || obj1.length < 1) {
		$(obj2).show();
		return false;
	} else {
		$(obj2).hide();
	}
	
	return true;
}

// 添加二级分类
function cmbAddOption(cmb, str, value) {
	
	// 创建一个option项
	var option = document.createElement("OPTION");
	// 添加option
	cmb.options.add(option);
	// 初始化名称
	option.innerHTML = str;

	if (value != null) {
		// 值
		option.value = value;
	}
}


